/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.mpd.musicjukebox.lib.actions;

import com.bff.mpd.utils.Utils;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import org.bff.javampd.MPDPlaylist;
import org.bff.javampd.objects.MPDAlbum;
import org.bff.javampd.objects.MPDArtist;

/**
 *
 * @author bfindeisen
 */
public class PlaylistInsertAlbumAction extends AbstractAction {

    private MPDPlaylist playlist;
    private MPDAlbum album;
    private MPDArtist artist;

    public PlaylistInsertAlbumAction(MPDPlaylist playlist,
            MPDAlbum album,
            MPDArtist artist) {
        super(Utils.getMessage("ACTION_INSERT_ALBUM_NAME"));
        this.album = album;
        this.artist = artist;
        this.playlist = playlist;
        putValue(Action.NAME, "Add Album");
        putValue(Action.SHORT_DESCRIPTION, Utils.getMessage("ACTION_INSERT_ALBUM_SHORT_DESC"));
    }

    public PlaylistInsertAlbumAction(MPDPlaylist playlist,
            MPDAlbum album) {
        this(playlist, album, null);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            if (getArtist() == null) {
                getPlaylist().insertAlbum(getAlbum());
            } else {
                getPlaylist().insertAlbum(getArtist(), getAlbum());
            }
        } catch (Exception ex) {
            Logger.getLogger(PlaylistInsertAlbumAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @return the playlist
     */
    public MPDPlaylist getPlaylist() {
        return playlist;
    }

    /**
     * @param playlist the playlist to set
     */
    public void setPlaylist(MPDPlaylist playlist) {
        this.playlist = playlist;
    }

    /**
     * @return the artist
     */
    public MPDAlbum getAlbum() {
        return album;
    }

    /**
     * @param artist the artist to set
     */
    public void setAlbum(MPDAlbum album) {
        this.album = album;
    }

    /**
     * @return the artist
     */
    public MPDArtist getArtist() {
        return artist;
    }

    /**
     * @param artist the artist to set
     */
    public void setArtist(MPDArtist artist) {
        this.artist = artist;
    }
}
